//
//  ZMYChangePasswdViewController.m
//  奇阅
//
//  Created by 奇阅科技 on 14-10-31.
//  Copyright (c) 2014年 奇阅科技. All rights reserved.
//

#import "ZMYChangePasswdViewController.h"
#import "Config.h"
#import "AppDelegate.h"
@interface ZMYChangePasswdViewController ()
@property (weak, nonatomic) IBOutlet UITextField *oldPasswdTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwdTextField;

@property (weak, nonatomic) IBOutlet UITextField *surePasswdTextField;
@property (weak, nonatomic) IBOutlet UIButton *changeButton;

@end

@implementation ZMYChangePasswdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setBarBackgroundImage:@"navBackground"];
    [self setTitleForNavigation:@"修改密码"];
    [self setLeftBackButtonForNavigation];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)changePassWD:(id)sender {
    if (self.oldPasswdTextField.text.length<1) {
        [AppDelegate showHUDAndHide:@"请输入原密码" view:self.view];
        return;
    }
    if (self.passwdTextField.text.length<6) {
        [AppDelegate showHUDAndHide:@"密码不能少于6位" view:self.view];
        return;
    }
    if (![self.passwdTextField.text isEqualToString:self.surePasswdTextField.text]) {
        [AppDelegate showHUDAndHide:@"新密码输入不一致，请重新输入" view:self.view];
        return;
    }
//    if ([self.oldPasswdTextField.text isEqualToString:self.passwdTextField.text]) {
//        [AppDelegate showHUDAndHide:@"新密码输入不一致，请重新输入" view:self.view];
//        return;
//    }
    self.changeButton.enabled = NO;
    [self.navigationController setSGProgressPercentage:80 andTintColor:YellowColor];
    [[ZMYNetWorkAPI default]changePasswd:self.oldPasswdTextField.text new:self.passwdTextField.text response:^(NSDictionary *resultDic) {
        [self.navigationController setSGProgressPercentage:100];
        [AppDelegate showHUDAndHide:@"修改成功" view:self.view];
        self.changeButton.enabled = YES;
    } error:^(NSString *errorStr) {
        [self.navigationController cancelSGProgress];
        [AppDelegate showHUDAndHide:errorStr view:self.view];
        self.changeButton.enabled = YES;
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
